package com.jfree.api.controller;

import com.jfree.entity.general.User;
import com.sun.org.apache.regexp.internal.RE;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/client-1")
public class ServiceController {

    @Value("${server.port}")
    private String port;

    @GetMapping("/getPort")
    public String getPort(HttpServletRequest request) {
        System.out.println("url=" + request.getRequestURL());
        return port;
    }

    @GetMapping("/client-1/getPort")
    public String bei(HttpServletRequest request) {
        System.out.println("url=" + request.getRequestURL());
        return "ward-" + port;
    }

    @PostMapping(value = "/user")
    public User user(@RequestBody User user) {
        user.setId(System.currentTimeMillis());
        return user;
    }

    @RequestMapping(value = "/getException")
    public String getException(Integer id) {
        System.out.println("---"+id+"----exception");
        int t = 1 / 0;
        return "<------SUCCESS------>" + id;

    }

    @RequestMapping(value = "/test")
    public String test(@RequestParam Integer id) {
        //int t = 1 / 0;
        return "<------testSUCCESS------>" + id;

    }

    @GetMapping(value = "/test1")
    public String test1(@RequestParam Integer id) {
        //int t = 1 / 0;
        return "<------test1------>" + id;

    }

    @RequestMapping(value = "/test2/{id}", method = RequestMethod.GET)
    public String test2(@PathVariable("id") Integer id) {
        //int t = 1 / 0;
        return "<------tes2------>" + id;

    }

    @GetMapping(value = "/test3/{id}")
    public String test3(@PathVariable("id") Integer id) {
        //int t = 1 / 0;
        return "<------tes3------>" + id;

    }

    @PostMapping(value = "/test4")
    public User test4(@RequestBody User user) {
        user.setName("test4");
        return user;
    }

    @RequestMapping(value = "/test5",method = RequestMethod.GET)
    public User test5(User user) {
        user.setName("test5");
        return user;
    }
}
